//
//  SFUserController.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/5/19.
//

import UIKit
  
class SFUserController: SFBaseController {

    // 是否是Tabbar里的个人页
    public var isTabMe: Bool = false
    
    fileprivate var header: SFUserHeader?
    
    fileprivate var coordinator: SFUserCoordinator?
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func setup() {
        super.setup()
        
        hideNavigationBar = true
        self.coordinator = SFUserCoordinator.init(vc: self)
        
        loadUserInfo()
    }
    
    func loadUserInfo() {
        guard let v = AppUser.userInfo() else { return }
        SFNetwork.post(url: kAPI_my_page, params: ["number":v.number ?? "","region":"北京"]) { response in
            switch response {
            case .success(let result):
                guard let info = UserInfo.deserialize(from: result.data) else {
                    self.reloadData()
                    return
                }
                AppUser.saveUser(info: info)
                self.coordinator?.userInfo = info
                self.reloadData()
                break
                
            case .fail(let error):
                break
            }
        }
    }
    
    func reloadData() {
        coordinator?.reloadComponent()
    }

}
